﻿using System.ComponentModel;
using AgFractal.Fractals;

namespace AgFractal
{
    public class MainPageData : INotifyPropertyChanged
    {
        public MainPageData Clone()
        {
            return (MainPageData)MemberwiseClone();
        }

        private double? _ZoomI1;
        public double? ZoomI1
        {
            get { return _ZoomI1; }
            set
            {
                if (value == _ZoomI1)
                    return;
                _ZoomI1 = value;
                NotifyChange("ZoomI1");
            }
        }

        private double? _ZoomI2;
        public double? ZoomI2
        {
            get { return _ZoomI2; }
            set
            {
                if (value == _ZoomI2)
                    return;
                _ZoomI2 = value;
                NotifyChange("ZoomI2");
            }
        }

        private double? _ZoomR1;
        public double? ZoomR1
        {
            get { return _ZoomR1; }
            set
            {
                if (value == _ZoomR1)
                    return;
                _ZoomR1 = value;
                NotifyChange("ZoomR1");
            }
        }

        private double? _ZoomR2;
        public double? ZoomR2
        {
            get { return _ZoomR2; }
            set
            {
                if (value == _ZoomR2)
                    return;
                _ZoomR2 = value;
                NotifyChange("ZoomR2");
            }
        }

        private double _I1;
        public double I1
        {
            get { return _I1; }
            set
            {
                if (value == _I1)
                    return;
                _I1 = value;
                NotifyChange("I1");
            }
        }

        private double _I2;
        public double I2
        {
            get { return _I2; }
            set
            {
                if (value == _I2)
                    return;
                _I2 = value;
                NotifyChange("I2");
            }
        }

        private double _R1;
        public double R1
        {
            get { return _R1; }
            set
            {
                if (value == _R1)
                    return;
                _R1 = value;
                NotifyChange("R1");
            }
        }

        private double _R2;
        public double R2
        {
            get { return _R2; }
            set
            {
                if (value == _R2)
                    return;
                _R2 = value;
                NotifyChange("R2");
            }
        }

        private short _Iteration = 150;
        public short Iteration
        {
            get { return _Iteration; }
            set
            {
                if (value == _Iteration)
                    return;
                if (value > 2560)
                    _Iteration = 2560;
                else
                    _Iteration = value;
                NotifyChange("Iteration");
            }
        }

        private IFractal _Fractal;
        public IFractal Fractal
        {
            get { return _Fractal; }
            set
            {
                if (value == _Fractal)
                    return;
                _Fractal = value;
                I1 = value.I1;
                I2 = value.I2;
                R1 = value.R1;
                R2 = value.R2;
                NotifyChange("Fractal");
                NotifyChange("HasParameter");
            }
        }

        private bool _AutoHide;
        public bool AutoHide
        {
            get { return _AutoHide; }
            set
            {
                if (value == _AutoHide)
                    return;
                _AutoHide = value;
                NotifyChange("AutoHide");
            }
        }  

        public bool HasParameter
        {
            get
            {
                return Fractal != null && Fractal.Parameter.GetEnumerator().MoveNext();
            }
        }


        #region INotifyPropertyChanged Members
        private void NotifyChange(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}